package com.Apo1o.service.Impl;

import com.Apo1o.bean.QuarantineRegistration;
import com.Apo1o.bean.ext.QExt;
import com.Apo1o.dao.QuarantineRegistrationMapper;
import com.Apo1o.exception.CustomerException;
import com.Apo1o.response.ResultCode;
import com.Apo1o.service.IQService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: Apo1o.
 * @Date: 2023/11/2-11-02-18:39
 * @Description： com.Apo1o.service.Impl
 */
@Service
@RequiredArgsConstructor
public class QServiceImpl implements IQService {
    private final QuarantineRegistrationMapper quarantineRegistrationMapper;

    @Override
    public PageInfo<QuarantineRegistration> findAll(Integer pageNum, Integer pageSize,String grMechanism,String bQualified) {
        if (pageNum==null || pageSize==null) throw  new CustomerException(ResultCode.PARAM_IS_EMPTY);
        PageHelper.startPage(pageNum, pageSize);
        List<QuarantineRegistration> all = quarantineRegistrationMapper.findAll(grMechanism, bQualified);
        PageInfo<QuarantineRegistration> page = new PageInfo<>(all);

        return page;

    }

    @Override
    public void saveOrUpdate(QuarantineRegistration q) {
        if (q.getGrId() == null){
            quarantineRegistrationMapper.insert(q);
        }else {
            quarantineRegistrationMapper.updateByPrimaryKey(q);
        }
    }

    @Override
    public void deleteById(Integer grId) {
        quarantineRegistrationMapper.deleteByPrimaryKey(grId);
    }

    @Override
    public void deleteByIdAll(List<Integer> list) {
            list.forEach(e-> deleteById(e));
    }
}
